package me.pinion.kit;


import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateKit {

    public static int getYear(){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR);
    }
    public static int getMonth(){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.MONTH) + 1;
    }


    public static int getDay(){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DATE);
    }

    public static int getWeekday(){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.DAY_OF_WEEK);
    }

    public static Long getCurrentLong(){
        return new Date().getTime();
    }

    public static Date recentStr2Date(String recent) {
        long now = new Date().getTime();
        long recentStamp;
        if ("HOUR".equals(recent)) {
            recentStamp = now - 1000 * 60 * 60;
        } else if ("DAY".equals(recent)) {
            recentStamp = now - 1000 * 60 * 60 * 24;
        } else if ("WEEK".equals(recent)) {
            recentStamp = now - 1000 * 60 * 60 * 24 * 7;
        } else {
            recentStamp = now - 1000 * 60 * 60 * 24 * 7 * 30;
        }
        return new Timestamp(recentStamp);
    }

    public static String toStr(Date date, String format){
        SimpleDateFormat fmt=new SimpleDateFormat(format);
        return fmt.format(date);
    }
}
